<?php

namespace Seller\Controller;

class SettingController extends BaseController {
    
    private $_model = nill;

    protected function _initialize() {
        parent::_initialize();
        $this->_model = M('customer_setting');
    }
    
    public function index() {
        if( IS_POST ) {
            $data = I('post.poster');
            $data['customer_id'] = $this->__seller_info['id'];
            $data = array_filter( $data );
            if( !$this->_model->where(array('customer_id' => $this->__seller_info['id']))->find() ) {
                $this->_model->add( $data );
            } else {
				!isset( $data['lock'] ) ? $data['lock'] = 0 : '';
				!isset( $data['agent'] ) ? $data['agent'] = 0 : '';
				!isset( $data['presell'] ) ? $data['presell'] = 0 : '';
				!isset( $data['wholesale'] ) ? $data['wholesale'] = 0 : '';
                $this->_model->where(array('customer_id' => $this->__seller_info['id']))->save( $data );
            }
            $this->success('配置成功');
            exit;
        }
        $this->assign('data' , $this->_model->where(array('customer_id' => $this->__seller_info['id']))->find());
        $this->display();
    }
    
}